﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;

namespace WpfHero
{
    public class GemSizeConverter : IValueConverter
    {

        public const double MillisecondsPerPixel = 10;

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null; 

            GemModel val = value as GemModel;
            
            if (val == null)
                throw new ArgumentException();

            //HACK: make ratio global, etc.
            double result = (val.EndAt.Value - val.StartAt).TotalMilliseconds / MillisecondsPerPixel;
            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class GemPauseConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return null;

            GemModel val = value as GemModel;

            if (val == null)
                throw new ArgumentException();

            TimeSpan ts = val.StartAt;

            if (val.Previous != null)
                ts -= val.Previous.EndAt.Value;

            return new Thickness(ts.TotalMilliseconds / GemSizeConverter.MillisecondsPerPixel, 0, 0, 0);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class BooleanToBoldConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (bool)value ? FontWeights.Bold : FontWeights.Normal;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    //public class EnumMatchToBooleanConverter : IValueConverter
    //{
    //    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    //    {
    //        if (targetType != typeof (bool))
    //            throw new ArgumentException("can only convert to bool");
              
    //        return value.ToString() == parameter.ToString();
    //    }

    //    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    //    {
    //        throw new NotImplementedException();
    //    }
    //}
}
